package com.beyond.trace.dy.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.beyond.trace.dy.domain.TraceDyBreed;
import com.beyond.trace.dy.service.ITraceDyBreedService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 品种管理Controller
 * 
 * @author Mr.Yao
 * @date 2022-04-08
 */
@RestController
@RequestMapping("/dy/breed")
@Api(value = "品种管理", tags = "品种管理")
public class TraceDyBreedController extends BaseController
{
    @Autowired
    private ITraceDyBreedService traceDyBreedService;

    //@PreAuthorize("@ss.hasPermi('dy:breed:list')")
    @GetMapping("/list")
    @ApiOperation("查询品种管理列表")
    public TableDataInfo list(TraceDyBreed traceDyBreed)
    {
        startPage();
        List<TraceDyBreed> list = traceDyBreedService.selectTraceDyBreedList(traceDyBreed);
        return getDataTable(list);
    }

    //@PreAuthorize("@ss.hasPermi('dy:breed:query')")
    @GetMapping(value = "/query")
    @ApiOperation("查询品种管理列表不分页")
    public AjaxResult getInfoQuery(TraceDyBreed traceDyBreed)
    {
        return AjaxResult.success(traceDyBreedService.selectTraceDyBreedList(traceDyBreed));
    }

    //@PreAuthorize("@ss.hasPermi('dy:breed:export')")
    @Log(title = "品种管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TraceDyBreed traceDyBreed)
    {
        List<TraceDyBreed> list = traceDyBreedService.selectTraceDyBreedList(traceDyBreed);
        ExcelUtil<TraceDyBreed> util = new ExcelUtil<TraceDyBreed>(TraceDyBreed.class);
        return util.exportExcel(list, "品种管理数据");
    }

    //@PreAuthorize("@ss.hasPermi('dy:breed:query')")
    @GetMapping(value = "/{breedId}")
    @ApiOperation("查询品种管理列表")
    public AjaxResult getInfo(@PathVariable("breedId") Long breedId)
    {
        return AjaxResult.success(traceDyBreedService.selectTraceDyBreedById(breedId));
    }

    //@PreAuthorize("@ss.hasPermi('dy:breed:add')")
    @Log(title = "品种管理", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增品种管理")
    public AjaxResult add(@RequestBody TraceDyBreed traceDyBreed)
    {
        return toAjax(traceDyBreedService.insertTraceDyBreed(traceDyBreed));
    }

    //@PreAuthorize("@ss.hasPermi('dy:breed:edit')")
    @Log(title = "品种管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改品种管理")
    public AjaxResult edit(@RequestBody TraceDyBreed traceDyBreed)
    {
        return toAjax(traceDyBreedService.updateTraceDyBreed(traceDyBreed));
    }

    //@PreAuthorize("@ss.hasPermi('dy:breed:remove')")
    @Log(title = "品种管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{breedIds}")
    @ApiOperation("删除品种管理")
    public AjaxResult remove(@PathVariable Long[] breedIds)
    {
        return toAjax(traceDyBreedService.deleteTraceDyBreedByIds(breedIds));
    }
}
